package lormi.meipin.service.impl;


import lormi.meipin.common.Page;
import lormi.meipin.dto.SchoolPageDto;
import lormi.meipin.entity.City;
import lormi.meipin.entity.School;
import lormi.meipin.exception.LMException;
import lormi.meipin.service.BaseService;
import lormi.meipin.service.ISchoolService;
import lormi.meipin.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchoolService extends BaseService implements ISchoolService{

	@Override
	public List<School> getPage(SchoolPageDto schoolPageDto) throws LMException {
//		List<SchoolPageVo> pageVos = new ArrayList<>();
		//区分省级和市级城市查询
		Integer level = 0 ;
		String code = "null" ;
		if (schoolPageDto.getCityid()!=null) {
			City city = cityMapper.selectByPrimaryKey(schoolPageDto.getCityid());
			if(city!=null){
				if("province".equals(city.getLevel())){
					level = 1;
					code = city.getProvinceid();
				}else if("city".equals(city.getLevel())){
					level = 2;
					code = city.getCityid();
				}
			}
		}
		
		Page page = new Page(schoolPageDto.getPagesize(),schoolPageDto.getPagenow(),
				schoolMapper.selectListCount(schoolPageDto.getSpecialclassid()+"", level, code));
		List<School> list = schoolMapper.selectList(schoolPageDto.getSpecialclassid()+"", level, code, page.getOffset(),page.getPageSize());
		for(School s:list){
			s.setSpecialclass(specialClassMapper.selectByList(StringUtil.getSplit(s.getSpecialclassids(), ";")));
		}
		return list;
	}

	
	
}
